<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定</title>
</head>
<body>
    <input type="button" onclick="on()" value="按钮1">
    <input type="button" id="btn2" value="按钮2">

</body>
<script>
    function on(){
        alert("按钮被点击了")
    }

    document.getElementById('btn2').onclick = function(){
        alert("按钮被点击了")
    }
</script>
</html>